package com.example.helloworld;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Dates {
    public static void main(String[] args) {
        Long dateTime = new Date().getTime();
        Integer hash = new Date().hashCode();

        System.out.println("当前的时间日期时间戳是："+dateTime);
        System.out.println("当前的时间hashCode是："+hash);

        // new 实例化时间
        Date date = new Date();
        System.out.println("当前的时间日期格式是："+date.toString());
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//        System.out.println("当前的时间日期是："+sdf.format(date));

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("当前的时间日期是："+sdf.format(date));

//        System.out.printf("%tY",date);  // 2024

//        try {
//            Thread.sleep(1000*3);  // 三秒后执行后面的程序
//            SimpleDateFormat sdfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//            System.out.println("当前的时间日期是："+sdfs.format(date));
//
//        } catch (Exception e){
//            System.out.println("Got an exception!");
//        }

//        try {
//            System.out.println(new Date( ) + "\n");
//            Thread.sleep(1000*3);   // 休眠3秒
//            System.out.println(new Date( ) + "\n");
//        } catch (Exception e) {
//            System.out.println("Got an exception!");
//        }

        // 计算间隔多少秒
        try {
            long strat = System.currentTimeMillis();
            System.out.println(new Date( ) + "\n");
            Thread.sleep(1000 * 3);
            System.out.println(new Date( ) + "\n");
//            long end = System.currentTimeMillis();
            long end = System.currentTimeMillis();
            long diff = end - strat;
            System.out.println("计算间隔"+ diff + "秒");
        } catch (Exception e){
            System.out.println("Got an exception!");
        }

    }
}
